<?php
/*
 * 商家参与活动 类
 * 
 */
namespace Home\Logic;

class Business_addLogic{

    public function __construct() {
        $this->b = D('Business_add');
    }

    public function add($data){
        $data['create_time'] = time();
    	$id =  $this->b->add($data);
    	return $id;
    }

    public function getBusinessById($id){
        return $this->b->where('id='.$id)->find();
    }
    
    /*获取提交申请的列表带分页*/
    public function getBusinessByPage($page,$limit=20){
        $total_page = ceil($this->countTotal()/$limit);
        $total_page = $total_page>0?$total_page:1;
        $page = $page>0?$page:1;
        $page = $page>$total_page?$total_page:$page;
        $list = $this->b->order('id desc')->limit(($page-1)*$limit,$limit)->select();
        $_Page  = new \Think\Page($total_page*$limit,$limit);
        $show  = $_Page->show();
        $show = str_replace('/index.php/','/',$show);
        return array('page'=>$show,'list'=>$list);
    }

    /*获取总数量*/
    public function countTotal(){
        return $this->b->count();
    }
    
    /*标示已处里*/
    public function dispose($id,$status){
        return $this->b->where('id='.$id)->save(array('status'=>$status));//status = 1 已处理的状态
    }
}